﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Utility.Attributes
{
    /// <summary>
    /// 代码-值-描述特性
    /// </summary>
    [AttributeUsage(AttributeTargets.All,AllowMultiple = false)]
    public class CodeValueDescriptionAttribute: Attribute
    {
        /// <summary>
        /// 代码-值-描述特性
        /// </summary>
        public CodeValueDescriptionAttribute()
        {

        }

        /// <summary>
        /// 代码-值-描述 特性
        /// </summary>
        /// <param name="order">排序号</param>
        /// <param name="code">代码</param>
        /// <param name="value">值</param>
        /// <param name="description">描述</param>
        public CodeValueDescriptionAttribute(int order = 0, string code = "", string value = "", string description = "")
        {
            this.Order = order;
            this.Code = code;
            this.Value = value;
            this.Description = description;
        }

        /// <summary>
        /// 排序号
        /// </summary>
        public int Order { get; set; } = 0;

        /// <summary>
        /// 代码
        /// </summary>
        public string Code { get; set; } = "Unknown Code";

        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; } = "Unknown Value";

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; } = "未定义信息";
    }

    /// <summary>
    /// 代码-值-特性描述 枚举信息
    /// </summary>
    public class EnumCodeValueDescriptionAttributeInfo<TEnum> where TEnum: struct,Enum
    {
        /// <summary>
        /// 枚举
        /// </summary>
        public TEnum? Enum { get; set; }

        /// <summary>
        /// 枚举名称
        /// </summary>
        public string? EnumName { get; set; }


        /// <summary>
        /// 枚举值
        /// </summary>
        public long? EnumValue { get; set; }


        /// <summary>
        /// 枚举排序
        /// </summary>
        public int? EnumSort { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int? Order { get; set; }

        /// <summary>
        /// 特性的代码
        /// </summary>
        public string? Code { get; set; }

        /// <summary>
        /// 特性的值
        /// </summary>
        public string? Value { get; set; }

        /// <summary>
        /// 特性的描述
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 全部数据项，用于下拉列表筛选
        /// <para>Code、EnumName = All, Enum = null,EnumSort、EnumValue、Order、Value = int.MinValue</para>
        /// </summary>
        public static EnumCodeValueDescriptionAttributeInfo<TEnum> AllDataItem
        {
            get
            {
                return new EnumCodeValueDescriptionAttributeInfo<TEnum>()
                {
                    Code = "All",
                    Description = "全部",
                    Enum = null,
                    EnumName = "All",
                    EnumSort = int.MinValue,
                    EnumValue = int.MinValue,
                    Order = int.MinValue ,
                    Value = int.MinValue.ToString(),
                };
            }
        }
    }
}
